package cn.wolfcode.luowowo.mgrsite.job;


import cn.wolfcode.luowowo.article.service.IStrategyDetailService;
import cn.wolfcode.luowowo.article.vo.StrategySVO;
import cn.wolfcode.luowowo.cache.service.IStrategyStatisVORedisService;
import cn.wolfcode.luowowo.cache.util.RedisKeys;
import cn.wolfcode.luowowo.cache.vo.StrategyStatisVO;
import cn.wolfcode.luowowo.common.util.BeanUtil;

import com.alibaba.dubbo.config.annotation.Reference;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.List;

//@Component
public class redisDataPersistenceJob {
    @Reference
    private IStrategyStatisVORedisService strategyStatisVORedisService;
    @Reference
    private IStrategyDetailService strategyDetailService;
    @Scheduled(cron = "0/20 * * * * ?")
    public void doWork(){
        //获取所有的vo对象
        List<StrategyStatisVO> list = strategyStatisVORedisService.getStrategyVOList(RedisKeys.STRATEGY_STATIS_VO.join("*"));
        //遍历获得里面的vo,并把他更新到strategyDetail中
        for (StrategyStatisVO vo : list) {
            StrategySVO strategySVO = new StrategySVO();
            BeanUtil.copyProperties(strategySVO,vo);
            strategyDetailService.updateStatis(strategySVO);
        }
    }
}
